import 'package:flutter/material.dart';
import 'pages/home_page.dart';
import 'pages/category_page.dart';
import 'pages/cart_page.dart';
import 'pages/profile_page.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _currentIndex = 0;
  final List<Widget> _pages = [
    const HomePage(),
    const CategoryPage(),
    const CartPage(),
    const ProfilePage(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _pages[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed,
        selectedItemColor: Colors.red,
        unselectedItemColor: Colors.grey,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
        items:[
          BottomNavigationBarItem(
            icon: Image.asset(
          'tabbar/home.png',
          width: 32,
          height: 32,
        ),
        activeIcon: Image.asset(
          'tabbar/home-active.png',
          width: 32,
          height: 32,
        ),
            label: '首页',
          ),
          BottomNavigationBarItem(
            icon: Image.asset(
          'tabbar/cate.png',
          width: 32,
          height: 32,
        ),
        activeIcon: Image.asset(
          'tabbar/cate-active.png',
          width: 32,
          height: 32,
        ),
            label: '分类',
          ),
          BottomNavigationBarItem(
             icon: Image.asset(
          'tabbar/cart.png',
          width: 32,
          height: 32,
        ),
        activeIcon: Image.asset(
          'tabbar/cart-active.png',
          width: 32,
          height: 32,
        ),
            label: '购物车',
          ),
          BottomNavigationBarItem(
             icon: Image.asset(
          'tabbar/user.png',
          width: 32,
          height: 32,
        ),
        activeIcon: Image.asset(
          'tabbar/user-active.png',
          width: 32,
          height: 32,
        ),
            label: '我的'
          ),
        ],
      ),
    );
  }
}
